/*
 *    Copyright (c) 2018-2025, nart All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: nart
 */
package com.nai365.nart.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nai365.nart.product.entity.Brand;
import com.nai365.nart.product.entity.BrandFans;
import com.nai365.nart.product.mapper.BrandMapper;
import com.nai365.nart.product.service.BrandFansService;
import com.nai365.nart.product.service.BrandService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 品牌
 *
 * @author baogs
 * @date 2022-07-01 11:05:46
 */
@Service
@AllArgsConstructor
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService {

	BrandFansService brandFansService;

	@Override
	public Brand getBrandInfo(Long brandId, Long userId) {
		Brand brand = getById(brandId);
		long count = brandFansService.count(new LambdaQueryWrapper<BrandFans>()
				.eq(BrandFans::getClubId, brandId)
				.eq(BrandFans::getFollow,true));

		if (userId != null) {
			long count1 = brandFansService.count(new LambdaQueryWrapper<BrandFans>()
					.eq(BrandFans::getClubId, brandId)
					.eq(BrandFans::getFollow,true)
					.eq(BrandFans::getUserId, userId));
			if (count1 > 0) {
				brand.setFollow(true);
			}
		}
		brand.setFansCount(count);
		return brand;
	}
}
